package com.dly.hope.controller;

import com.dly.hope.annotation.LoginRole;
import com.dly.hope.annotation.SysLog;
import com.dly.hope.constant.R;
import com.dly.hope.model.ro.CommentRo;
import com.dly.hope.model.ro.GetUserShowRo;
import com.dly.hope.model.ro.ReleaseRo;
import com.dly.hope.model.vo.ShowVo;
import com.dly.hope.service.ShowService;
import com.dly.hope.pageUtils.Page;
import com.dly.hope.pageUtils.PageRo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Api(tags = "朋友圈相关接口")
@RequestMapping(value = "/show")
public class ShowController extends BaseController{

    @Resource
    private ShowService showService;

    @PostMapping("/release")
    @ApiOperation(value = "发布说说")
    @LoginRole
    private ResponseEntity<R<Void>> release(@RequestBody ReleaseRo releaseRo){
        showService.release(getCurrentUserId(), releaseRo);
        return operate(this::success);
    }

    @PostMapping("/getAllShow")
    @ApiOperation(value = "获取所有说说")
    @LoginRole
    private ResponseEntity<R<Page<ShowVo>>> getAllShow(PageRo pageRo){
        return operate(()->this.successDate(showService.getAllShow(getCurrentUserId(), pageRo)));
    }

    @PostMapping("/getUserShow")
    @ApiOperation(value = "获取特定人所有说说")
    private ResponseEntity<R<Page<ShowVo>>> getUserShow(GetUserShowRo getUserShowRo){
        return operate(()->this.successDate(showService.getUserShow(getCurrentUserId() ,getUserShowRo)));
    }

    @PostMapping("/praise")
    @ApiOperation(value = "点赞/取消点赞")
    @LoginRole
    public ResponseEntity<R<Void>> praise(String showId){
        showService.praise(getCurrentUserId(), showId);
        return operate(this::success);
    }

    @PostMapping("/comment")
    @ApiOperation(value = "评论")
    @LoginRole
    public ResponseEntity<R<Void>> comment(CommentRo commentRo){
        showService.comment(commentRo);
        return operate(this::success);
    }

    @PostMapping("/deleteShow")
    @ApiOperation(value = "删除动态")
    @LoginRole
    public ResponseEntity<R<Void>> deleteShow(String showId){
        showService.deleteShow(showId, getCurrentUserId());
        return operate(this::success);
    }
}
